<template>
    <div class="deal">
        <!-- <van-nav-bar :title="$t('news.title')" leftArrow @click-left="_return"/> -->
        <van-tabs v-model="active">
          <van-tab :title="$t('news.news')">
             <div class="news_main" >
              <ul>
                <li v-for="item in newsData" @click="showNews(item)">
                    <div class="code">
                        <h3>{{item.title}}</h3>
                        <p v-html="item.content"></p>
                        <span>{{item.add_time}}</span>
                    </div>
                    <div class="newImg">
                        <img :src="item.web+item.img" alt="">
                    </div>
                </li>    
              </ul>
            </div>
          </van-tab>
          <van-tab :title="$t('news.Not')">
             <div class="news_main" >
              <ul>
                <li v-for="item in noticeData" @click="showNews(item)">
                    <div class="code">
                        <h3>{{item.title}}</h3>
                        <p v-html="item.content"></p>
                        <span>{{item.add_time}}</span>
                    </div>
                    <div class="newImg">
                        <img :src="item.web+item.img" alt="">
                    </div>
                </li>    
              </ul>
            </div>
          </van-tab>
        </van-tabs>
        <van-popup v-model="show" closeable close-icon="close" position="bottom" :style="{ height: '80%' }">
        <div class="newMain">
            <h3>{{detail.title}}</h3>
            <span>{{detail.add_time}}</span>
            <img :src="detail.web+detail.img" alt="">
            <p v-html="detail.content"></p>
    </div>
        </van-popup>
    </div>
</template>

<script>
    import moment from 'moment'
    export default {
        data() {
            return {
                newsData:[],
                 active: 0,
                 detail:[],
                 show:false,
                 noticeData:[]
            }
        },
        methods: {
            _return(){
                this.$router.go(-1);//返回上一层
            },
            getNews(type){
                this.$api.post('index/newslist?cid='+type)
                    .then(res =>{
                        if(type==1){
                        this.newsData = res.detail.list;
                        this.newsData.map(item => {
                            item.add_time = moment(item.create_at*1000).format('YYYY.MM.DD')
                        })
                        }else{
                            this.noticeData = res.detail.list;
                            this.noticeData.map(item => {
                                item.add_time = moment(item.create_at*1000).format('YYYY.MM.DD')
                            })
                        }
                    })
            },
            getData(){
                this.getNews(2);
                this.getNews(1);

            },
            showNews(e){
                this.$api.get('index/newsdetail?news_id='+e.id)
                    .then(res =>{
                        this.detail=res.detail
                        this.show=true
                    })

            }
        },
        created() {
             this.getData()
        },
        mounted() {
            this.$emit('disappear')
        },
    }
</script>

<style lang="stylus" scoped>
    .news_main{
    width: 100%;
    margin:10px 0 60px;
}
.news_main ul li{
    width: 95%;
    background: #FFF;
    margin:  5px auto 5px;
    display: flex;
    display: -webkit-flex;
    flex-wrap: nowrap;
    justify-content: center;
    border-radius:10px;
 	border:1px solid #ebebeb
}
.news_main ul li .code{
    width: 50%;
    margin-left: 2%;
    padding: 10px 0;
}
.news_main ul li .newImg{
    width: 40%;
    padding: 10px ;
    height:120px;
}
.news_main ul li .newImg img{
    width: 100%;
    height: 100%;
    display: block;
    border-radius:10px;
}

.news_main ul li .code h3{
    font-size: 16px;
    line-height: 24px;
  	overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.news_main ul li .code p{
    font-size: 12px;
    height:50px;
    color: #2D3141;
    padding: 2px 0 ;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;

}
.news_main ul li .code span{
    font-size: 12px;
    color: #2D3141;
}
.newMain{
    width: 96%;
    margin: 10px auto 0;
    background: #FFF;
}
.newMain h3{
    font-size: 16px;
    margin-top 40px
}
.newMain span{
    color: #BABBBD;
    font-size: 12px;
    padding: 10px 0 5px;
}
.newMain img{
    width: 100%;
    height: 236px;
    padding: 10px 0;
    display: block;
}
.newMain p{
    color: #565656;
    font-size: 16px;

}

</style>
<style >
.van-tabs__line{
  background-color: rgb(34, 193, 150) !important;
}
</style>